Attribute VB_Name = "states"
Option Explicit

Public StateSlot As Integer 'current save slot
Public Sub SaveListBox(Directory As String, TheList As ListBox)
    Dim SaveList As Long
    On Error Resume Next
    Open Directory$ For Output As #1
    For SaveList& = 0 To TheList.ListCount - 1
        Print #1, TheList.List(SaveList&)
    Next SaveList&
    Close #1
End Sub


Public Sub StateLoad()

  If fileexists(App.Path & "\folders\save states\" & ROM_Name$ & ".vs" & StateSlot & "") <> True Then 'checks to see if it exists
    Exit Sub
  End If

  Open App.Path & "\folders\save states\" & ROM_Name$ & ".vs" & StateSlot & "" For Binary As #1 'opens the save state

  Get #1, , cartRam
  'Get #1, , cartRom
  Get #1, , frame_two_rom
  'Get #1, , glMemAddrDiv256
  'Get #1, , Mul4000
  'Get #1, , number_of_pages
  'Get #1, , pages
  'Get #1, , ShiftRight
  'Get #1, , ShiftLeft
  Get #1, , SRAM
  Get #1, , VRAM
  Get #1, , CRAM
  Get #1, , vdpreg
  Get #1, , status
  Get #1, , first_byte
  Get #1, , command_byte
  Get #1, , location
  Get #1, , operation
  Get #1, , read_buffer
  Get #1, , counter
  Get #1, , lineint
  Get #1, , frameint
  'Get #1, , bg_priority
  'Get #1, , display
  Get #1, , regA
  Get #1, , regHL
  Get #1, , regB
  Get #1, , regC
  Get #1, , regDE
  Get #1, , regAF_
  Get #1, , regHL_
  Get #1, , regBC_
  Get #1, , regDE_
  Get #1, , regIX
  Get #1, , regIY
  Get #1, , regID
  Get #1, , fC
  Get #1, , fN
  Get #1, , fPV
  Get #1, , f3
  Get #1, , fH
  Get #1, , f5
  Get #1, , fZ
  Get #1, , fS
  Get #1, , intI
  Get #1, , intR
  Get #1, , intRTemp
  Get #1, , intIFF1
  Get #1, , intIFF2
  Get #1, , intIM
  Get #1, , halt
  Get #1, , regSP
  Get #1, , regPC
  'Get #1, , Parity
  Get #1, , irqsetLine

  Close #1

End Sub
Public Sub StateSave()

  Open App.Path & "\folders\save states\" & ROM_Name$ & ".vs" & StateSlot & "" For Binary As #1 'opens the file for writing

  Put #1, , cartRam
  'Put #1, , cartRom
  Put #1, , frame_two_rom
  'put #1, , glMemAddrDiv256
  'put #1, , Mul4000
  'Put #1, , number_of_pages
  'Put #1, , pages
  'put #1, , ShiftRight
  'put #1, , ShiftLeft
  Put #1, , SRAM
  Put #1, , VRAM
  Put #1, , CRAM
  Put #1, , vdpreg
  Put #1, , status
  Put #1, , first_byte
  Put #1, , command_byte
  Put #1, , location
  Put #1, , operation
  Put #1, , read_buffer
  Put #1, , counter
  Put #1, , lineint
  Put #1, , frameint
  'Put #1, , bg_priority
  'Put #1, , display
  Put #1, , regA
  Put #1, , regHL
  Put #1, , regB
  Put #1, , regC
  Put #1, , regDE
  Put #1, , regAF_
  Put #1, , regHL_
  Put #1, , regBC_
  Put #1, , regDE_
  Put #1, , regIX
  Put #1, , regIY
  Put #1, , regID
  Put #1, , fC
  Put #1, , fN
  Put #1, , fPV
  Put #1, , f3
  Put #1, , fH
  Put #1, , f5
  Put #1, , fZ
  Put #1, , fS
  Put #1, , intI
  Put #1, , intR
  Put #1, , intRTemp
  Put #1, , intIFF1
  Put #1, , intIFF2
  Put #1, , intIM
  Put #1, , halt
  Put #1, , regSP
  Put #1, , regPC
  'put #1, , Parity
  Put #1, , irqsetLine

  Close #1

End Sub
